/*
   @Copyright:LibreOJ
   @Author:   tjyemail
   @Problem:  https://loj.ac/problem/119
   @Language: C++
   @Datetime: 20-08-13 15:07
   */
// Bellman Ford with Queue (SPFA), time O(V*E) 24ms

#include <bits/stdc++.h>
using namespace std;

#define VERTEX 2505
#define EDGE 6205
// linked forward star
struct Edge {
	int v, c, next;
	Edge(int v=0, int c=0, int next=-1):v(v), c(c), next(next){}
} edges[EDGE*2];
int heads[VERTEX];
int ie = 0;
inline void add(int u, int v, int c) {
	edges[ie] = Edge(v, c, heads[u]);
	heads[u] = ie++;
}
//int path[VERTEX];
//int enque[VERTEX]; // check if it has negtive circle
int dists[VERTEX];

void spfa(int v, int s, int t) {
	for(int i=0; i++<v; dists[i]=INT_MAX);
	dists[s] = 0;
	queue<int> vs;
	for(vs.push(s); !vs.empty(); vs.pop()) {
		s = vs.front();
		//if (++enque[s]==v) break; // has negtive circle
		// update dists[s's adjacency]
		for(int k=heads[s]; k!=-1; k=edges[k].next) {
			if (dists[edges[k].v] > dists[s]+edges[k].c) {
				dists[edges[k].v] = dists[s]+edges[k].c;
				//path[edges[k].v] = s;
				vs.push(edges[k].v);
			}
		}
	}
	printf("%d\n", dists[t]);
}

int main()
{
	int v, e, s, t, a, b, c; // vertex edge, start -> target
	scanf("%d %d %d %d", &v, &e, &s, &t);
	memset(heads, -1, sizeof(heads));
	for(int i=0; i<e; ++i) {
		scanf("%d %d %d", &a, &b, &c); // a->b, cost
		add(a, b, c);
		add(b, a, c); // undirect graph
	}
	spfa(v, s, t);
	// shortest path s -> ... -> t
	//for(printf("%d",a=t); a!=s; printf("<-%d",a=path[a]));
	//printf("\n");
	return 0;
}
